xen/arm: smmuv3: Avoid open coded arithmetic in memory allocation
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Tue, 23 Aug 2022 14:44:18 +0000 (15:44 +0100)
committerJulien Grall <jgrall@amazon.com>
Tue, 6 Sep 2022 16:43:35 +0000 (17:43 +0100)
Backport Linux commit 98b64741d611. This is the clean backport without
any changes

kmalloc_array()/kcalloc() should be used to avoid potential overflow
when a multiplication is needed to compute the size of the requested
memory.

So turn a devm_kzalloc()+explicit size computation into an
equivalent devm_kcalloc().

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Acked-by: Robin Murphy <robin.murphy@arm.com>
Link: https://lore.kernel.org/r/3f7b9b202c6b6f5edc234ab7af5f208fbf8bc944.1644274051.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Will Deacon <will@kernel.org>
Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 98b64741d611
Signed-off-by: Rahul Singh <rahul.singh@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
xen/drivers/passthrough/arm/smmu-v3.c

index b8ca4b0a244da603e2eeee7103ea40a1c76f7ca0..9c9f4630090ef5e930a9163a787667f6cbbb73a0 100644 (file)
@@ -1644,10 +1644,10 @@ static int arm_smmu_init_l1_strtab(struct arm_smmu_device *smmu)
 {
        unsigned int i;
        struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg;
-       size_t size = sizeof(*cfg->l1_desc) * cfg->num_l1_ents;
        void *strtab = smmu->strtab_cfg.strtab;
 
-       cfg->l1_desc = _xzalloc(size, sizeof(void *));
+       cfg->l1_desc = _xzalloc_array(sizeof(*cfg->l1_desc), sizeof(void *),
+                                                                 cfg->num_l1_ents);
        if (!cfg->l1_desc)
                return -ENOMEM;